setwd("C:/Users/Daniel de Kadt/Dropbox/Projects/SA_cohort_effects/replication")
library(foreign)
library(ggplot2)
library(grid)
library(gridExtra)
d = read.dta("idasa_1994_ddk12.dta")

dat = subset(d, d$race!=4)
dat = na.omit(dat)

dat$Race = "Black"
dat$Race = ifelse(dat$race==2, "White", dat$Race)
dat$Race = ifelse(dat$race==3, "Coloured", dat$Race)

table.dat = table(dat$Race, dat$sa_conditions)
table.dat2 = table(dat$Race, dat$econ_conditions)
table.dat3 = table(dat$Race, dat$deklerk_rating)
table.dat4 = table(dat$Race, dat$NP_close)
table.dat5 = table(dat$Race, dat$ANC_close)

xtable(prop.table(table.dat,1))
xtable(prop.table(table.dat2,1))
xtable(prop.table(table.dat3,1))
xtable(prop.table(table.dat4,1))
xtable(prop.table(table.dat5,1))

mean(dat$sa_conditions[dat$Race=="Black"])
mean(dat$sa_conditions[dat$Race=="White"])
mean(dat$sa_conditions[dat$Race=="Coloured"])

mean(dat$econ_conditions[dat$Race=="Black"])
mean(dat$econ_conditions[dat$Race=="White"])
mean(dat$econ_conditions[dat$Race=="Coloured"])

mean(dat$deklerk_rating[dat$Race=="Black"])
mean(dat$deklerk_rating[dat$Race=="White"])
mean(dat$deklerk_rating[dat$Race=="Coloured"])
